﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TrinitySequenceAssembly
{
    class DebruijnGraph
    {
        int m_KmerLength;
        string m_SequenceFilePath;
        public DebruijnGraph(int kmerLength, string sequenceFilePath)
        {
            m_KmerLength = kmerLength;
            m_SequenceFilePath = sequenceFilePath;
        }

        private void CreateCellForDebruijnNode(List<DebruijnNode> partialDebruijnNodeList)
        {

        }

        public void BuildGraph()
        {
            FastaReader reader = new FastaReader(m_SequenceFilePath);
            SequenceReadParser readParser = new SequenceReadParser(m_KmerLength);
            int batchSaveNum = 1024 * 1024;
            List<DebruijnNode> partialDebruijnNodeList = new List<DebruijnNode>();
            long sequenceReadID = 0;
            string sequenceRead;
            while (true)
            {
                sequenceRead = reader.Read();
                if (sequenceRead != null)
                {
                    DebruijnNode[] kmersInRead = readParser.Parse(sequenceRead, sequenceReadID);
                    if (kmersInRead != null)
                    {
                        partialDebruijnNodeList.AddRange(kmersInRead);
                        sequenceReadID += 1;
                        if (partialDebruijnNodeList.Count >= batchSaveNum)
                        {
                            CreateCellForDebruijnNode(partialDebruijnNodeList);
                            partialDebruijnNodeList.Clear();
                        }
                    }
                }
                else
                {
                    break;
                }
            }
            reader.Close();
        }
    }
}
